export default {
    data(){
        return{
            msg:''
        }
    },
    methods:{
        register(){
            if(this.$refs.username.value!='' && this.$refs.password.value!=''){
                // console.log(this.$refs.username.value)
                // console.log(this.$refs.password.value)
                var that=this
                var a=1
                this.$store.state.user.map(x=>{
                    if(x.username==that.$refs.username.value){
                        a=0
                        return this.msg="用户已存在"
                    }
                })
                if(a){
                    this.$store.state.user.push({username:this.$refs.username.value,password:this.$refs.password.value})
                    this.msg="注册成功"
                    this.$router.push({ path: '/login' })
                }
                // console.log(this.$store.state.user)
            }else{
                this.msg="用户名和密码不能为空"
            }
        }
    }
}